package com.jcfk.eam.controller.mt;

import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.eam.controller.parent.EamProductAssetModelController;
import com.jcfk.eam.domain.dto.base.EamProductAssetModelDTO;
import com.jcfk.eam.domain.query.base.EamProductAssetModelQuery;
import com.jcfk.eam.enums.AssetKind;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * 产品与检具清单 服务接口
 *
 * @author yql
 * @email 522891237@gqq.com
 * @date 2024-07-25
 */
@Api(tags = {"产品与检具清单"})
@RestController
@RequestMapping("mtproductassetmodel")
public class MtProductAssetModelController {
    @Autowired
    private EamProductAssetModelController eamProductAssetModelController;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamProductAssetModelQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询产品与资产型号")
    @PostMapping("/queryByPage")
    public RetPage<EamProductAssetModelDTO> queryByPage(@RequestBody ReqPageParam<EamProductAssetModelQuery> requestParam) {
        requestParam.getData().setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamProductAssetModelController.queryByPage(requestParam);
    }


    /**
     *  产品与资产型号
     * 根据id 查询详情
     */
    @ApiOperation("查询产品与资产型号")
    @GetMapping("/get/{id}")
    public RetResult<EamProductAssetModelDTO> get(@PathVariable("id") String id) {
        return eamProductAssetModelController.get(id);
    }

    /**
     * 添加/更新管理产品与资产型号
     */
    @ApiOperation("保存产品与资产型号")
    @PostMapping("/save")
    @RequestLogHeader(modular = "产品与资产型号管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamProductAssetModelDTO eamProductAssetModel) {
        eamProductAssetModel.setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        return eamProductAssetModelController.save(eamProductAssetModel);
    }

    /**
     *  批量删除产品与资产型号
     */
    @ApiOperation("批量删除产品与资产型号")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "产品与资产型号管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamProductAssetModelDTO eamProductAssetModel) {
        return eamProductAssetModelController.delete(eamProductAssetModel);
    }


    @PostMapping("export")
    @ApiOperation("导出")
    public void export(@RequestBody EamProductAssetModelQuery requestParam, HttpServletResponse response) throws Exception {
        requestParam.setAssetKind(AssetKind.MEASURING_TOOL.getValue());
        eamProductAssetModelController.export(requestParam,response);
    }

    /**
     * 下载模板
     */
    @PostMapping("exportTemp")
    @ApiOperation("下载模板")
    public void exportTemp(HttpServletResponse response) throws Exception {
        eamProductAssetModelController.exportTemp(response);
    }


    /**
     *  删除产品与资产型号
     */
    @ApiOperation("删除产品与资产型号")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "产品与资产型号管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        return eamProductAssetModelController.deleteItem(id);
    }
}
